package models

import (
	"gorm.io/gorm"
	"time"
)

type Video struct {
	gorm.Model
	Title   string    `json:"title"`
	Name    string    `json:"name"`
	Address string    `json:"address"`
	Times   time.Time `json:"times"`
}

func ListVideo(page int, pageSize int, title string) ([]Video, int64, error) {
	var videos []Video
	var total int64
	query := DB.Model(Video{})
	if title != "" {
		query = query.Where("title like ?", "%"+title+"%")
	}
	if err = query.Count(&total).Error; err != nil {
		return nil, 0, err
	}
	if err = query.Offset((page - 1) * pageSize).Limit(pageSize).Find(&videos).Error; err != nil {
		return nil, 0, err
	}
	return videos, total, nil
}
